
/**
 * 订单管理 js
 */
var common = {};

common.paginationQuery = function(pn) {
	var name = $("#searchKeyWords").val();
	var params = {};
	params.orderNumber = name;
	params.taskStatus = $("#_taskStatus").val();
	params.year = $("#datetimepicker").val();
	params.businessId = $("#_businessId").val();
	params.page = pn;
	server.ajaxLoadTableList({
		url:server.url + "/manage/orderNumber/list",	// post请求url路径--必填
		params:params,
		paginationTable:'data-table',
		paginationFooter:'data-pagination',
		checkbox:true,
		columns:[{
			field:'orderNumber',	
			title:'订单号',
			width:120,
			formatter:function(value,row){
				var result = '<a href="javascript:server.openModalBox(\'/manage/orderNumber/view/' + row.id + '/1\',\'查看\',800);">' + value + '</a>';
				return result;
			}
		},{
			field:'hcBusiness.businessName',
			title:'业务',
			width:130
		},{
			field:'year',
			title:'年度',
			width:80
		},{
			field:'hcDisabledInformation.name',
			title:'服务对象',
			width:100
		},{
			field:'hcServiceItem.serviceName',
			title:'服务项目',
			width:130
		},{
			field:'taskStatus',
			title:'订单状态',
			width:100,
			formatter:function(value,row){
				var result = "--";
				if(value === "0"){
					result = "待接单";	
				}else if(value === "1"){
					result = "已接单";
				}else if(value === "2"){
					result = "进行中";
				}else if(value === "3"){
					result = "已完成";
				}else if(value === "4"){
					result = "已结束";
				}
				return result;
			}
		},{
			field:'updatedUser.userName',
			title:'更新人',
			width:100
		},{
			field:'updateTime',
			title:'更新时间',
			width:125,
			formatter:function(value,row){
				var updateTime = '--';
				if(value != null && value > 0){
					updateTime = new Date(value).format('yyyy-MM-dd hh:mm:ss');
				}
				return updateTime;
			}
		},{
			field:'action',	// 如果此为操作按钮时, field则应写成active, 此值固定!!!
			title:'操作',
			width:60,
			formatter:function(value,row){
				// 操作按钮
				var operationButtons = '<div class="btn-group">';
                operationButtons += '<a class="btn btn-xs btn-azure dropdown-toggle" data-toggle="dropdown" aria-expanded="false">操作 <i class="fa fa-angle-down"></i></a>';
                operationButtons += '<ul class="dropdown-menu dropdown-azure">';
                operationButtons +=  '<li><a href="javascript:server.openModalBox(\'/manage/orderNumber/view/' + row.id + '/1\',\'查看\',800);"> 查看</a></li>';
                operationButtons +=  '<li><a href="javascript:server.deleteObject(\''+row.id+'\',\'/manage/serviceManage/company/delete\',common.paginationQuery,server.currentPage);"> 删除</a></li>';
                operationButtons += '</ul>';
                operationButtons +=  '</div>';
				return operationButtons;
			}
		}]
	});
}

common.validate = function(){
	if(verify.isNull($("#companyName").val())){
		server.alert("公司名称不可为空");
		return false;
	}
	
	if(verify.isNull($("#socialCreditCode").val())){
		server.alert("统一社会信用代码不可为空");
		return false;
	}
	if(verify.isNull($("#legalPerson").val())){
		server.alert("法人不可为空 ");
		return false;
	}
	
	if(!verify.isIdentityCard($("#legalPersonIdNumber").val())){
		server.alert("请输入格式正确的身份证号");
		return false;
	}
	if(!verify.isMobileOrPhone($("#officeContactNumber").val())){
		server.alert("请输入格式正确的联系方式");
		return false;
	}
	if(verify.isNull($("#district").val())){
		server.alert("请选择区、县");
		return false;
	}
	return true;
}

common.loadBusinessByYear = function(year){
	if(year == null || year == ''){
		var $sel = $("#_businessId");
		$sel.empty().append('<option value="">请选择业务</option>');
		return;
	}
	$.ajax({
		url: server.url + "/manage/orderNumber/getBusinessByYear",
		type: 'POST',
		data:{
			'year' : year
		},
		dataType : 'json',
		success : function(data){
			var $sel = $("#_businessId");
			$sel.empty().append('<option value="">请选择业务</option>');
			var businessList = data.entity;
			$.each(businessList,function(index, item){
				var opt = $("<option />");
				opt.val(item.id).text(item.businessName);
				$sel.append(opt);
			});
		}
	})
	
}
